package cn.lliiooll.mt;

import cn.lliiooll.evt.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.UUID;

public class ShiFu implements MentorPlayer{

    private Player p;

    public ShiFu(Player p){
        this.p = p;
    }

    @Override
    public ShiFu getShiFu() {
        return new ShiFu(p);
    }

    public TuDi getTuDi(){
        if(!has()){
            return null;
        }
        return new TuDi(Bukkit.getPlayer((UUID)MentorFile.get(p.getUniqueId().toString(),"tudi")));
    }

    @Override
    public boolean del() {
        if(!has()){
            return false;
        }
        MentorFile.set(p.getUniqueId().toString(),"tudi",null);
        Bukkit.getPluginManager().callEvent(new PlayerDelPupilEvent(p,new TuDi(Bukkit.getPlayer((UUID) MentorFile.get(this.p.getUniqueId().toString(),"tudi")))));
        return true;
    }

    @Override
    public boolean change(Player p) {
        if(!has()){
            return false;
        }
        MentorFile.set(this.p.getUniqueId().toString(),"tudi",p.getUniqueId().toString());
        Bukkit.getPluginManager().callEvent(new PlayerChangePupilEvent(p,new TuDi(Bukkit.getPlayer((UUID) MentorFile.get(this.p.getUniqueId().toString(),"tudi")))));
        return true;
    }

    @Override
    public boolean add(Player p) {
        if(has()){
            return false;
        }
        MentorFile.set(this.p.getUniqueId().toString(),"tudi",p.getUniqueId().toString());
        Bukkit.getPluginManager().callEvent(new PlayerMakePupilEvent(this.p,new TuDi(p)));
        return true;
    }

    @Override
    public boolean has() {
        return MentorFile.hasValue(p.getUniqueId().toString(),"tudi");
    }

    @Override
    public Player getPlayer() {
        return p;
    }

}
